import Vue from 'vue';

// v-clickOutside="()=>reset(param),": 元素之外的点击

Vue.directive('clickOutside', {
  bind(el,binding,vnode){
    function clickOutsideHandler(e){
      if(el.contains(e.target)){
        return false;
      }
      if(binding.expression){
        binding.value(e)
      }
    }

    el._vueClickOutside_ =clickOutsideHandler
    document.addEventListener('click',clickOutsideHandler)
  },
  unbind(el,binding){
    document.removeEventListener('click',el._vueClickOutside_)
    delete el._vueClickOutside_
  }
})